package br.ufpe.cin.redes.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ufpe.cin.redes.business.NegocioUsuario;
import br.ufpe.cin.redes.dados.Usuario;
import br.ufpe.cin.redes.fachada.Fachada;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * Servlet pra registrar
*/
public class RegistrarServlet extends HttpServlet{
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String login = req.getParameter("login");
		String senha = req.getParameter("senha");
		RequestDispatcher dispatcher = req.getRequestDispatcher("/registrar.jsp");
		if(Fachada.getFachada().BuscarUsuario(login) != null)
		{
			req.setAttribute("ErroUsuarioJaRegistrado", "");
			dispatcher.forward(req, resp);
		}
		else
		{
			req.setAttribute("UsuarioRegistradoComSucesso", "");
			Fachada.getFachada().InserirUsuario(new Usuario(login, senha));
			dispatcher.forward(req, resp);
		}
		
	}
}
